<template>
	<view class="cu-modal bottom-modal" :class="tempShowModel==true?'show':''">
		<view class="cu-dialog">
			<view class="cu-bar bg-white justify-end">
				<view class="content">{{infoType==1?'买家评论':'卖家评论'}}</view>
				<view class="action" @tap="closeWin">
					<text class="cuIcon-roundclose text-gray"></text>
				</view>
			</view>
			<scroll-view style="width:100%;height:50vh">
				
				<mescroll-uni v-if="tempShowModel" :fixed="false" ref="mescrollRef" @init="mescrollInit" :up="upOption" @down="downCallback" @up="upCallback">
					
					<!-- 详情 begin -->
					<view class="cu-list menu-avatar">
						
						<view class="cu-item" v-for="(item,index) in list" v-if="list.length > 0" :key="index">
							<view class="cu-avatar round lg" :style="'background-image:url('+item.writer.avatar+');'"></view>
							<view class="content">
								<view>{{item.msg}}</view>
								<view class="text-sm text-grey flex">
									{{item.city}}的{{infoType==1?'买家':'卖家'}}
									{{item.createdAt}}
								</view>
							</view>
							<view class="action">
								<view class="margin-lr-xs cu-tag radius sm bg-red" v-if="item.score>0">好评</view>
								<view class="margin-lr-xs cu-tag radius sm bg-grey" v-else>一般</view>
							</view>
						</view>
						
					</view>
					<!-- 详情 end -->
				
				</mescroll-uni>
				
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				upOption: {
					page: {
						size: 6 // 每页数据的数量,默认10
					},
					empty: {
						tip: '暂无相关数据'
					},					
					textNoMore:'暂无更多数据'
				 },
				 tempShowModel:false,
				 list:[],
				 url:'/sell_info_order/page_user_evaluation'
			};
		},
		name: 'info-win',
		props: {
			infoType: {
				type: Number,
				default: 1
			},
			showModel: {
				type: [Boolean, String],
				default: false
			},
			userId:{
				type: Number,
				default: -1
			},
		},
		watch:{
			infoType(val){
				if(val==1){
					this.url='/sell_info_order/page_user_evaluation'
				}else{
					this.url='/buy_info_order/page_user_evaluation'
				}
			},
			showModel(val){
				if(val==true){
					this.tempShowModel=val
				}				
			}
		},
		created() {
			this.tempShowModel=this.showModel
			if(this.infoType==1){
				this.url='/sell_info_order/page_user_evaluation'
			}else{
				this.url='/buy_info_order/page_user_evaluation'
			}
		},
		methods: {
			closeWin(){
				this.tempShowModel=false
				this.list=[]
				this.$nextTick(()=>{
					this.$emit("closeWin")
				})
			},
			//数据操作类-------------------------
			//页面数据请求事件
			tranNetDataToPageData(page,count,list){
				let _this=this				
				if(page == 1){
					_this.list = [] //如果是第一页需手动置空列表
				}
				_this.list = _this.list.concat(list)
			},
			upCallback(page) {
				let _this=this
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				
				var data,url
				data={
					"p":pageNum,
					"s":pageSize,
					"user":_this.userId
				}
				
				_this.$api.post(this.url,data).then(res => {
					if (res.code == 200){
						let curPageLen=res.data.records.length
						let totalSize=res.data.total;
						
						_this.tranNetDataToPageData(pageNum,res.data.total,res.data.records)
						
						_this.mescroll.endBySize(curPageLen, totalSize);					
						setTimeout(()=>{
							_this.mescroll.endSuccess(curPageLen)
						},20)
					}else{
						console.log(res.msg)
						uni.showToast({
							icon: 'none',
							title: '网络异常'
						})
					}
					
				}).catch(error=>{
					console.log(error)
					uni.showToast({
						icon: 'none',
						title: '网络异常'
					})
				})
			},
		}
	}
</script>

<style>
</style>